/**
 * Created by baiguiren on 1/16/17.
 */


const async = require('async');

const test_arr = [1, 2, 3, 4, 5];

async.detect(test_arr, (item, callback) => {
    setTimeout(()=>{
        console.log('finish ' + item);
        callback(null, item >= 10);
    }, Math.random() * 100);
}, (err, results)=> {
    if (results) {
        console.log('there is some value greater than or equal 3.');
    } else {
        console.log('all values in collection are less than 3');
    }
});

async.detectSeries(test_arr, (item, callback) => {
    setTimeout(()=>{
        console.log('finish ' + item);
        callback(null, item >= 10);
    }, Math.random() * 100);
}, (err, results)=> {
    if (results) {
        console.log('there is some value greater than or equal 3.');
    } else {
        console.log('all values in collection are less than 3');
    }
});